package org.finesys.quartz.support;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.finesys.common.quartz.core.exception.TaskException;
import org.finesys.quartz.entity.SysJob;
import org.springframework.stereotype.Component;

/**
 * Rest方法 包调用实现
 */
@Component
@Slf4j
public class TaskInvokeRestServiceImpl implements TaskInvokeService {

    @Override
    public void invoke(SysJob sysJob) throws TaskException {
        try {
            HttpRequest httpRequest = HttpUtil.createGet(sysJob.getExecutePath());
            httpRequest.execute();
        } catch (Exception e) {
            log.error("定时任务TaskInvokeRestServiceImpl异常,执行任务：{}", sysJob.getExecutePath());
            throw new TaskException("定时任务TaskInvokeRestServiceImpl业务执行失败,任务：" + sysJob.getExecutePath());
        }
    }
}
